﻿using System;
using System.Data;
using System.Collections.Generic;
using BookSystem.Model;
namespace BookSystem.BLL
{
    /// <summary>
    /// 业务逻辑类Book 的摘要说明。
    /// </summary>
    public class Book
    {
        private readonly BookSystem.DAL.Book dal = new BookSystem.DAL.Book();
        public Book()
        { }
        #region  成员方法
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(BookSystem.Model.Book model)
        {
            dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(BookSystem.Model.Book model)
        {
            dal.Update(model);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public BookSystem.Model.Book GetModel(int uuid)
        {

            return dal.GetModel(uuid);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<BookSystem.Model.Book> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            List<BookSystem.Model.Book> modelList = new List<BookSystem.Model.Book>();
            int rowsCount = ds.Tables[0].Rows.Count;
            if (rowsCount > 0)
            {
                BookSystem.Model.Book model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new BookSystem.Model.Book();
                    if (ds.Tables[0].Rows[n]["uuid"].ToString() != "")
                    {
                        model.uuid = int.Parse(ds.Tables[0].Rows[n]["uuid"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["purchasecount"].ToString() != "")
                    {
                        model.purchasecount = int.Parse(ds.Tables[0].Rows[n]["purchasecount"].ToString());
                    }
                    model.content = ds.Tables[0].Rows[n]["content"].ToString();
                    model.publisher = ds.Tables[0].Rows[n]["publisher"].ToString();
                    model.class_uuid = ds.Tables[0].Rows[n]["class_uuid"].ToString();
                    model.storefile = ds.Tables[0].Rows[n]["storefile"].ToString();
                    model.booknumber = ds.Tables[0].Rows[n]["booknumber"].ToString();
                    model.bookname = ds.Tables[0].Rows[n]["bookname"].ToString();
                    model.author = ds.Tables[0].Rows[n]["author"].ToString();
                    model.book_language = ds.Tables[0].Rows[n]["book_language"].ToString();
                    model.isbn = ds.Tables[0].Rows[n]["isbn"].ToString();
                    if (ds.Tables[0].Rows[n]["purchasetime"].ToString() != "")
                    {
                        model.purchasetime = DateTime.Parse(ds.Tables[0].Rows[n]["purchasetime"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["publishtime"].ToString() != "")
                    {
                        model.publishtime = DateTime.Parse(ds.Tables[0].Rows[n]["publishtime"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["price"].ToString() != "")
                    {
                        model.price = double.Parse(ds.Tables[0].Rows[n]["price"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  成员方法
    }
}

